package com.yixin.ystartlibrary.base;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;

import com.yixin.ystartlibrary.utils.LogUtils;

/**
 * Created by Administration on 2018/4/12.
 */

public class BaseLazyFragment extends BaseFragment {
    private boolean isFragmentVisible;
    private boolean isReuseView;
    private boolean isFirstVisible;
    private View rootView;
    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        LogUtils.i("onCreate");
        initVariable();
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        LogUtils.i("onViewCreated");
            if (getUserVisibleHint()) {
                if (isFirstVisible) {
                    onFragmentFirstVisible();
                    isFirstVisible = false;
                }
                isFragmentVisible = true;
            }

    }

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        LogUtils.i("setUserVisibleHint"+isFirstVisible);

        if (isFirstVisible && isVisibleToUser) {//第一次加载
            onFragmentFirstVisible();
            isFirstVisible = false;
        }
        if (isVisibleToUser) {//不可见到可见
            LogUtils.i("isVisibleToUser:"+isVisibleToUser);
            onFragmentVisibleChange(true);
            isFragmentVisible = true;
            return;
        }
        if (isFragmentVisible) {//可见到不可见
            LogUtils.i("isVisibleToUser:"+isVisibleToUser);
            isFragmentVisible = false;
            onFragmentVisibleChange(false);
        }

    }




    @Override
    protected int getContextView() {
        return 0;
    }

    @Override
    protected void init() {

    }

    @Override
    protected void initBundleData() {

    }
    private void initVariable() {
        isFirstVisible = true;
        isFragmentVisible = false;

    }
    protected void onFragmentFirstVisible() {

    }
    protected void onFragmentVisibleChange(boolean isVisible) {

    }


}
